package io.github.liuyuhao412.manager.request;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponse<T> {
	private int code;
	private T data;
	private String error;

	public static <T> ApiResponse<T> success(T data) {
		ApiResponse<T> response = new ApiResponse<>();
		response.setCode(0);
		response.setData(data);
		response.setError(null);
		return response;
	}

	public static <T> ApiResponse<T> error(int code, String errorMsg) {
		ApiResponse<T> response = new ApiResponse<>();
		response.setCode(code);
		response.setData(null);
		response.setError(errorMsg);
		return response;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getError() {
		return error;
	}

	public void setError(String error) {
		this.error = error;
	}
}
